﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarchEstate.Manager.BusinesEntity;
using MarchEstate.Manager.Dao.Room;

namespace MarchEstate.Manager.ObjectModel.Room
{
    public class Building : AbstractBuilding
    {
        private AreaRoomDao areaRoomDao = null;

        public Building()
        { }

        public override void InitDao()
        {
            base.InitDao();
            areaRoomDao = NewDao<AreaRoomDao>();

        }

        public override bool Save(string type)
        {
            if (type == "add")
            {
                if (areaRoomDao.ExistBuildingModel(this.BuildingCode))
                {
                    throw new Exception("输入的代码已存在，请重新输入！");
                }
                return areaRoomDao.AddBuilding(this) > 0;
            }
            else if (type == "alter")
            {
                return areaRoomDao.UpdateBuilding(this) > 0;
            }
            return true;
        }

        public override bool Delete(string _buildingCode)
        {
            return areaRoomDao.DeleteBuilding(_buildingCode);
        }

        public override List<AbstractBuilding> GetBuildingList(string _areaCode)
        {
            return areaRoomDao.GetBuildingList(_areaCode);
        }

        public override System.Data.DataTable GetBuildingFieldList(string _areaCode)
        {
            return areaRoomDao.GetBuildingFieldList(_areaCode);
        }

        public override AbstractBuilding GetBuilding(string _buildingCode)
        {
            return areaRoomDao.GetBuilding(_buildingCode);
        }
    }
}
